package org.lq.ssm.controller;

import org.lq.ssm.Web.HttpResult;
import org.lq.ssm.dto.UserDTO;
import org.lq.ssm.po.UserPO;
import org.lq.ssm.service.UserService;
import org.lq.ssm.vo.UserVO;
import org.lq.ssm.vo.mapper.UserVOMapper;
import org.lq.ssm.vo.util.VOPopulate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedList;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("getalluser.do")
    public HttpResult<List<UserVO>> getAllUser(
            @RequestParam(name = "level",defaultValue = "1") int level,
            @RequestParam(name = "id" , defaultValue = "1") long id
    ){
        List<UserDTO> allUsers = userService.getAllUser(level,id);
        List<UserVO> userVOS = new LinkedList<>();
        for (UserDTO userDTO : allUsers){
            UserVO userVO = UserVOMapper.INSTANCE.specialUserDTOToVO(userDTO);
            userVOS.add(userVO);
        }
        return HttpResult.ok(userVOS,"数据没问题");
    }
}
